export {
    GoodsInfo,
    GoodsBanner,
};

/**
 * 商品池商品信息
 */
class GoodsInfo {
    id: number;
    goodsName: string;                  // 商品名称
    introduce: string;                  // 简介
    batchNumber: string;                // 批次
    capacity: number;                   // 容量，一箱多少瓶，不能小于1
    expirationDate: string;             // 过期日期
    preSalePrice: number;               // 商品价格：给供销商的价格
    maxPreSalePrice: number;            // 最大价格
    minPreSalePrice: number;            // 最小价格
    suggestedRetailPrice: number;       // 建议零售价
    maxSuggestedRetailPrice: number;    // 零售最大价
    minSuggestedRetailPrice: number;    // 零售最小价
    totalStock: number;                 // 总库存
    soldStock: number;                  // 已售
    goodsImageUrl: string;              // 商品图片url
    goodsImageBase64: string;           // 商品图片base64编码
    content: string;                    // 富文本内容
    goodsBanners: GoodsBanner[] = [];   // 商品banner

    initGoodsInfo(msg: any) {
        this.id = msg.id;
        this.goodsName = msg.goodsName;
        this.introduce = msg.introduce;
        this.batchNumber = msg.batchNumber;
        this.capacity = msg.capacity;
        this.expirationDate = msg.expirationDate;
        this.preSalePrice = msg.preSalePrice / 100;
        this.maxPreSalePrice = msg.maxPreSalePrice / 100;
        this.minPreSalePrice = msg.minPreSalePrice / 100;
        this.suggestedRetailPrice = msg.suggestedRetailPrice / 100;
        this.maxSuggestedRetailPrice = msg.maxSuggestedRetailPrice / 100;
        this.minSuggestedRetailPrice = msg.minSuggestedRetailPrice / 100;
        this.totalStock = msg.totalStock;
        this.content = msg.content;
        this.goodsImageUrl = msg.goodsImageUrl;
        this.goodsImageBase64 = msg.goodsImageBase64;
        this.goodsBanners = msg.goodsBanners;
    }

    clone(goodsInfo: GoodsInfo) {
        this.id = goodsInfo.id;
        this.goodsName = goodsInfo.goodsName;
        this.introduce = goodsInfo.introduce;
        this.batchNumber = goodsInfo.batchNumber;
        this.capacity = goodsInfo.capacity;
        this.expirationDate = goodsInfo.expirationDate + ' 00:00:00';
        this.preSalePrice = parseInt('' + goodsInfo.preSalePrice * 100, 10);
        this.maxPreSalePrice = parseInt('' + goodsInfo.maxPreSalePrice * 100, 10);
        this.minPreSalePrice = parseInt('' + goodsInfo.minPreSalePrice * 100, 10);
        this.suggestedRetailPrice = parseInt('' + goodsInfo.suggestedRetailPrice * 100, 10);
        this.maxSuggestedRetailPrice = parseInt('' + goodsInfo.maxSuggestedRetailPrice * 100, 10);
        this.minSuggestedRetailPrice = parseInt('' + goodsInfo.minSuggestedRetailPrice * 100, 10);
        this.totalStock = goodsInfo.totalStock;
        this.content = goodsInfo.content;
        this.goodsImageUrl = goodsInfo.goodsImageUrl;
        this.goodsImageBase64 = goodsInfo.goodsImageBase64;
        this.goodsBanners = goodsInfo.goodsBanners;
    }

    checkGoodsInfo(): string {
        if (!this.goodsName) {
            return '请填写商品名称';
        }
        if (!this.introduce) {
            return '请填写简介';
        }
        if (!this.batchNumber) {
            return '请填写批次';
        }
        if (!this.capacity) {
            return '请填写容量';
        }
        if (!this.expirationDate) {
            return '过期日期';
        }
        if (!this.preSalePrice) {
            return '请填写商品价格';
        }
        if (!this.maxPreSalePrice) {
            return '请填写最大价格';
        }
        if (!this.minPreSalePrice) {
            return '请填写最小价格';
        }
        if (!this.suggestedRetailPrice) {
            return '请填写建议零售价';
        }
        if (!this.maxSuggestedRetailPrice) {
            return '请填写零售最大价';
        }
        if (!this.minSuggestedRetailPrice) {
            return '请填写零售最小价';
        }
        if (!this.content) {
            return '请填写商品详细内容';
        }
        if (!this.goodsImageUrl && !this.goodsImageBase64) {
            return '请选择商品图片';
        }
        return null;
    }

}

class GoodsBanner {
    id: number;
    url: string;

    constructor(id: number, url: string) {
        this.id = id;
        this.url = url;
    }

}


